package com.ruoyi.framework.web.service;


import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.SendSMSUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Component
public class SmsService {

    @Value("${sms.userName}")
    private  String userName;
    @Value("${sms.password}")
    private  String password;
    @Value("${sms.url}")
    private  String url;

    public String smsSend(String phoneNumber,String content){

        long timeStamp = System.currentTimeMillis();
        String userName = "石家庄立业软件";
        String password = "KyJmQx6QEGDv";
        String sign = DigestUtils.md5Hex(userName + content + timeStamp + DigestUtils.md5Hex(password)).toLowerCase();
        List<String> phoneList = new ArrayList<>();
        phoneList.add(phoneNumber);
        JSONObject json = new JSONObject();
        json.put("userName", userName);
        json.put("content", content);
        json.put("timestamp", timeStamp);
        json.put("phoneList", phoneList);
        json.put("sign", sign);
        try {
            String post = SendSMSUtil.sendHttp(url, "POST", json.toString(), "UTF-8");
            System.out.println(post);
            return post;
        } catch (IOException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }
}
